package com.cloud.lawcase.api.web;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cloud.lawcase.api.bean.DictBean;
import com.cloud.lawcase.api.entity.TcDicDef;
import com.cloud.lawcase.api.service.LawDictService;
import com.cloud.lawcase.common.result.Quokka;

import springfox.documentation.annotations.ApiIgnore;
@ApiIgnore
@RestController
@RequestMapping("lawcase/api/dict")
public class LawDictController {

	@Autowired
	private LawDictService lawDictService;

	@GetMapping("list")
	public Quokka listDictDef() {
		return new Quokka(true, lawDictService.listDictDef());
	}

	@PostMapping("listtree")
	public Quokka listDictTree(@RequestBody TcDicDef def) {
		return new Quokka(true, lawDictService.listDictTree(def));
	}

	@PostMapping("saveupdate")
	public Quokka saveUpdateDict(@RequestBody DictBean bean) {
		lawDictService.refreshCache();
		return new Quokka(true, lawDictService.saveUpdateDict(bean));
	}

	@PostMapping("delete")
	public Quokka deleteDict(@RequestBody DictBean bean) {
		lawDictService.refreshCache();
		lawDictService.deleteDict(bean);
		return new Quokka(true);
	}
	
	@GetMapping("loaddetail")
	public Quokka load(int dicId, int pkId) {
		return new Quokka(true, lawDictService.loadDictDetail(dicId, pkId));
	}
	
	@GetMapping("listsxitems")
	public Quokka listSxItems() {
		return new Quokka(true, lawDictService.listSxItems());
	}

	@GetMapping("listall")
	public Quokka listAll() {
		Map<String, Object> results = new HashMap<String, Object>();
		results.put("lawType", lawDictService.listLawTypeItems());// 分类
		results.put("lawRegion", lawDictService.listLawRegionItems());// 区划
		results.put("lawDept", lawDictService.listLawPublishDeptItems());// 发布部门
		results.put("xljb", lawDictService.listLawEffectLevelItems());// 效力级别
		results.put("sx", lawDictService.listSxItems());// 时效性
		results.put("lawGroup", lawDictService.listAllGroups());// 分组
		return new Quokka(true, results);
	}
	
	@GetMapping("listexcutetypes")
	public Quokka listExcuteTypes(){
		return new Quokka(true, lawDictService.listLawExcuteTypes());
	}
	
	@GetMapping("listcausedics")
	public Quokka listCauseEditDics(){
		Map<String, Object> results = new HashMap<String, Object>();
		results.put("excuteTypes", lawDictService.listLawExcuteTypes());
		results.put("funcUnits", lawDictService.listFuncUnits());
		results.put("funcLevels", lawDictService.listFuncUnitLevels());
		return new Quokka(true, results);
	}
	
	@GetMapping("grouptree")
	public Quokka listGroupTree(){
		return new Quokka(true, lawDictService.listGroupTree());
	}
	
	@GetMapping("listlawregion")
	public Quokka listLawRegion(){
		return new Quokka(true, lawDictService.listLawRegionItems());
	}
}
